package com.bluebench.bigul.domain.graphics.simple.polygon;

import java.util.ArrayList;
import java.util.List;

import com.bluebench.bigul.domain.graphics.Graphic;
import com.bluebench.bigul.domain.graphics.Line;
import com.bluebench.bigul.domain.graphics.Point;
import com.itextpdf.text.pdf.PdfContentByte;

public class Scalene extends Triangle{
	
	public Scalene(PdfContentByte pdfContent) {
		super(pdfContent);	
	}	

	@Override
	public Polygon build(Point start, List<Float> sides) {
		
		float x = start.getX();
		float y = start.getY();
				
		float side1 = sides.get(0);
		float side2 = sides.get(1);
		float side3 = sides.get(2);
		
		canvas.moveTo(x, y);        
	    canvas.lineTo(x + side1, y);
	    
	    double angle = getIncludedAngle(sides,Triangle.B);
	    float x3 = (float)(x + side1 - (side2*Math.cos(angle))); 
	    float y3 = (float)(y + side2*Math.sin(angle));
	    canvas.lineTo(x3,y3);
	    
	    vertices.add(new Point(x,y));
	    vertices.add(new Point(x + side1, y));
	    vertices.add(new Point(x3,y3));
	    
	    this.sides.add(new Line(side1));
	    this.sides.add(new Line(side2));
	    this.sides.add(new Line(side3));
	    
	    return this;
		
	}

	@Override
	protected boolean validate() {		
		return true;
	}

	@Override
	public Graphic concentric(float distance, boolean in) {
		float x = vertices.get(0).getX();
		float y = vertices.get(0).getY();
		Point start=null;
		float side1=0;
		float side2=0;
		float side3=0;
		List<Float> edges = null;
		if(in){
			start = new Point(x+distance,y+distance);
			//TODO : validate that lenght > 2d
			side1 = sides.get(0).getLength() - (2*distance);
			side2 = sides.get(1).getLength() - (2*distance);
			side3 = sides.get(2).getLength() - (2*distance);
			edges = new ArrayList<Float>();
		}else{
			start = new Point(x-distance,y-distance);
			//TODO : validate that lenght > 2d
			side1 = sides.get(0).getLength() - (2*distance);
			side2 = sides.get(1).getLength() - (2*distance);
			side3 = sides.get(2).getLength() - (2*distance);
			edges = new ArrayList<Float>();
		}
		edges.add(side1);
		edges.add(side2);
		edges.add(side3);

		return build(start,edges);	
	}

	@Override
	public Graphic copy(float distance, int direction) {
		// TODO Auto-generated method stub
		return null;
	}
	
	

}
